// pages/shop_add/shop_add.js
const api = require('../../utils/util.js');
const service = require('../../utils/service.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataObj: {
      shopInfo: '',
      shopData: '',
      goods_id: '', //编辑商品传过来的商品id
      edit: 0, //--是否是编辑商品页面
      name: '', //--商品标题
      hot: 0, //--是否热门
      group_booking: 0, //--是否拼团
      description: '', //--商品详情
      cat_id: '', //--系统类目ID
      category_id: '', //--分类ID
      commission1_rate: '', //--一级佣金
      commission2_rate: '',
      genuine: 1,
      speed_return: 0,
      seven_reason: 1,
      yzc_type: 0, //--0为普通商品 1为YZC商品
      on_sale: 1, // 0下架 1上架
    }, //--上传的数据对象
    swiperImageArr: [], //--轮播图图片数组
    swiperIndex: 0, //--当前swiper图片指针
    num: 8, //--已上传图片数量
    textNum: 0,
    templateList: ['1'],
    data: [], //--对象数组（价格、型号、库存等信息）
    goodsDescriptionData: [], //保存商品详情数组
    sys_cat_name: '', //系统类目名称
    tags_tag: false,
    classify_tag: false, //新建分类模态框
    classfiyList: [], //分类列表
    classify_selected_name: '', //分类选择名称
    showClassifyModel: false, //新建分类输入框
    classify_name: '', //新建分类名称
    classify_selected_id: '', //选中的分类ID
    brokerage_tag: false, //是否已经提示
    focus_tag: false, //是否聚焦
    ruleCheck: true, //是否同意规则
  },

  test: function(inds, abc) {
    console.log(inds);
    this.setData({
      ['data[' + inds + '].imgSpec']: abc
    })
    console.log(this.data.data)
  },

  //swiper指针改变事件
  goSettingCurrentIndex: function(e) {
    this.setData({
      swiperIndex: e.detail.current
    })
  },

  //--打开添加图片页面（点击swiper）
  openImgManage: function() {
    if (this.data.swiperImageArr.length) {
      wx.navigateTo({
        url: './shop_add_img_manage/shop_add_img_manage?swiperImageStr=' + this.data.swiperImageArr + '&swiperIndex=' + this.data.swiperIndex,
        success: function(res) {},
      })
    } else {
      this.chooseImage()
    }

  },

  //--打开添加图片页面（点击按钮）
  chooseImage: function() {
    let _this = this;
    wx.showActionSheet({
      itemList: ['拍照模式', '手机相册'],
      success: function(res) {
        if (res.tapIndex == 0) {
          api.upLoadImg(_this.data.num, 'camera', function(res) {
            console.log(res)
            let imgList = _this.data.swiperImageArr.slice();
            let num = _this.data.num;

            imgList.push(res)
            num--;

            _this.setData({
              swiperImageArr: imgList,
              num: num,
              swiperIndex: imgList.length - 1
            })
          })
        } else if (res.tapIndex == 1) {
          api.upLoadImg(_this.data.num, 'album', function(res) {
            let imgList = _this.data.swiperImageArr.slice();
            let num = _this.data.num;

            for (let i = 0; i < res.length; i++) {
              imgList.push(res[i])
            }
            num -= res.length;

            _this.setData({
              swiperImageArr: imgList,
              num: num,
              swiperIndex: imgList.length - 1
            })
          })
        }
      }
    })
  },

  //--监听textarea事件
  textareaInput: function(e) {
    this.setData({
      textNum: e.detail.value.length,
      ['dataObj.name']: e.detail.value
    })
  },

  //--监听热门拼团选项
  shopGroupChange: function(e) {
    // console.log(e)
    let shop_group_arr = e.detail.value;
    let isGro = 0;
    let isRec = 0;
    switch (shop_group_arr.length) {
      case 1:
        if (shop_group_arr[0] == 'isRecommend') {
          isRec = 1;
          isGro = 0;
        } else if (shop_group_arr[0] == 'isGroup') {
          isRec = 0;
          isGro = 1;
        }
        break;
      case 2:
        isRec = 1;
        isGro = 1;
        break;
      default:
        isRec = 0;
        isGro = 0;
        break;
    }
    this.setData({
      ['dataObj.hot']: isRec,
      ['dataObj.group_booking']: isGro
    })
  },

  //--打开上传图片页面
  openImgSelect: function(e) {
    let inds = e.currentTarget.dataset.inds;
    if (this.data.num == 8) {
      api.toast('请先添加商品图片');
      return;
    } else {
      wx.navigateTo({
        url: './shop_add_img_select/shop_add_img_select?swiperImageStr=' + this.data.swiperImageArr + '&inds=' + inds,
        success: function(res) {},
      })
    }
  },

  //--输入拼团价格
  inputGroupPrice: function(e) {
    console.log(e);
    let inds = e.currentTarget.dataset.inds;
    let val = e.detail.value;
    let data = this.data.data;
    data[inds].groupPrice = val;
    this.setData({
      data: data
    })
    console.log(this.data.data)
  },

  //--选择拼团人数
  groupNumSelect: function(e) {
    let _this = this;
    let inds = e.currentTarget.dataset.inds;
    let data = this.data.data;
    wx.showActionSheet({
      itemList: ['2人', '3人'],
      success: function(res) {
        if (res.tapIndex == 0) {
          data[inds].groupNum = 2;
          _this.setData({
            data: data
          })
        } else if (res.tapIndex == 1) {
          data[inds].groupNum = 3;
          _this.setData({
            data: data
          })
        }
      },
    })
  },

  //--输入价格
  inputPrice: function(e) {
    console.log(e);
    let inds = e.currentTarget.dataset.inds;
    let val = e.detail.value;
    let data = this.data.data;
    data[inds].goodsPrice = val;
    this.setData({
      data: data
    })
    console.log(this.data.data)
  },

  //--输入YZC
  inputYZCPrice: function(e) {
    console.log(e);
    let inds = e.currentTarget.dataset.inds;
    let val = e.detail.value;
    let data = this.data.data;
    data[inds].yzcPrice = val;
    this.setData({
      data: data
    })
    console.log(this.data.data)
  },

  //--输入型号
  inputGoodsSpec: function(e) {
    console.log(e);
    let inds = e.currentTarget.dataset.inds;
    let val = e.detail.value;
    let data = this.data.data;
    data[inds].goodsSpec = val;
    this.setData({
      data: data
    })
    console.log(this.data.data)
  },

  //--输入库存
  inputGoodsNum: function(e) {
    console.log(e);
    let inds = e.currentTarget.dataset.inds;
    let val = e.detail.value;
    let data = this.data.data;
    data[inds].goodsNum = val;
    this.setData({
      data: data
    })
    console.log(this.data.data)
  },

  //--添加商品型号
  addGoods: function(e) {
    // let inds = e.currentTarget.dataset.inds;
    let templateList = this.data.templateList.slice();
    let data = this.data.data.slice();
    templateList.push('1')
    let obj = {
      groupPrice: "",
      killPrice: "",
      groupNum: "",
      goodsPrice: "",
      marketPrice: "",
      yzcPrice: "",
      goodsSpec: "",
      goodsNum: "",
      imgSpec: ""
    }
    data.push(obj)
    this.setData({
      templateList: templateList,
      data: data
    })
    console.log(this.data.data);
  },

  //--删除商品型号
  addModelDel: function(e) {
    let inds = e.currentTarget.dataset.inds;
    let templateList = this.data.templateList.slice();
    let data = this.data.data.slice();
    templateList.splice(inds, 1);
    data.splice(inds, 1);
    this.setData({
      templateList: templateList,
      data: data
    })
  },

  //--打开商品详情添加/编辑页面
  goodsDetail: function(e) {
    let contentArr = this.data.goodsDescriptionData;
    if (Array.isArray(contentArr)) {
      for (var i = 0; i < contentArr.length; i++) {
        if (contentArr[i].indexOf('<p>') != -1) {
          var str = contentArr[i];

          str = str.slice(3);
          console.log(str + "3333");
          str = str.slice(0, -4);
          console.log(str + "4444");
          contentArr[i] = str;

        } else if (contentArr[i].indexOf('<img') != -1) {
          var str = contentArr[i];

          str = str.slice(10);
          console.log(str + "10");
          str = str.slice(0, -3);
          console.log(str + "3");

          contentArr[i] = str;
          console.log(str);
        }
      }
    }

    // console.log(contentArr);

    wx.navigateTo({
      url: "./shop_add_detail/shop_add_detail?goodsDescriptionData=" + contentArr,
      success: function(res) {},
    })
  },

  //--打开系统类目页面
  openSysCategory: function(e) {
    wx.navigateTo({
      url: './shop_add_sys_cat/shop_add_sys_cat',
      success: function(res) {},
    })
  },

  //--阻止滚动条穿透
  myCatchTouch: function() {
    return;
  },

  //--分类选择列表显示事件
  goodsClassfiy: function() {
    let _this = this;

    api.ajax(service.url('categoryGetAll'), {
      unionid: this.data.shopData.shop_unionid,
      token: this.data.shopData.token,
      token_key: this.data.shopData.token_key,
      shop_code: this.data.shopInfo.shop_code
    }, function(res) {
      console.log(res)
      _this.setData({
        classify_tag: true,
        classfiyList: res.data
      })
    })

  },

  //--分类选择列表隐藏事件
  close_batch_classfiy: function() {
    this.setData({
      classify_tag: false,
      classify_selected_id: '',
      classify_selected_name: '',
    })
  },

  //--新建分类框显示事件
  newClassfiy: function() {
    this.setData({
      showClassifyModel: true
    })
  },

  //--分类选择变动事件（radio-group原生事件）
  calssifyChange: function(e) {
    let classify_id = e.detail.value;
    let name = '';
    if (classify_id != '') {
      name = e.currentTarget.dataset.classifyName;
    }

    this.setData({
      classify_selected_id: classify_id,
      classify_selected_name: name
    })
  },

  //分类选择事件（catchtap事件）
  classifyTap: function(e) {
    // let name = e.currentTarget.dataset.classifyName;
    // this.setData({
    //   classify_selected_name: name
    // })
  },

  //--新建分类选择确认事件
  classifySure: function() {
    this.setData({
      classify_tag: false,
      ['dataObj.category_id']: this.data.classify_selected_id
    })
    console.log(this.data.dataObj)
  },

  //--新建分类框隐藏事件
  hideClassifyModel: function() {
    this.setData({
      showClassifyModel: false
    })
  },

  //--获取新建分类名称事件
  getClassfiyName: function(e) {
    let name = e.detail.value;
    this.setData({
      classify_name: name
    })
  },

  //--新建分类确定事件
  sureAddClassfiy: function() {
    let _this = this;

    api.ajax(service.url('categoryAdd'), {
      unionid: this.data.shopData.shop_unionid,
      token: this.data.shopData.token,
      token_key: this.data.shopData.token_key,
      shop_code: this.data.shopInfo.shop_code,
      name: this.data.classify_name
    }, function(res) {
      console.log(res)
      _this.hideClassifyModel();

      api.ajax(service.url('categoryGetAll'), {
        unionid: _this.data.shopData.shop_unionid,
        token: _this.data.shopData.token,
        token_key: _this.data.shopData.token_key,
        shop_code: _this.data.shopInfo.shop_code
      }, function(res) {
        console.log(res)
        _this.setData({
          classfiyList: res.data
        })
      })
    })
  },

  //--点击佣金显示提示
  BrokeragePop: function() {
    let _this = this;
    wx.showModal({
      title: '佣金说明',
      content: '一级佣金\n商家对商品分享者给予该商品成交价格百分比的分佣\n二级分佣\n商家对商品分享者上级给予该商品成交价格百分比的分佣',
      showCancel: false,
      confirmText: '我知道了',
      success: function (res) {
        if (res.confirm) {
          _this.setData({
            brokerage_tag: true,
            focus: true
          })
        }
      }
    })
    // if (this.data.brokerage_tag) {
    //   return;
    // } else {
      
    // }
  },

  //--获取一级佣金
  getFirstBrokerage: function(e) {
    let commission1_rate = e.detail.value;
    this.setData({
      ['dataObj.commission1_rate']: commission1_rate
    })
  },

  //--获取二级佣金
  getSecondBrokerage: function(e) {
    let commission2_rate = e.detail.value;
    this.setData({
      ['dataObj.commission2_rate']: commission2_rate
    })
  },

  //设置正品保证
  setGenuine: function(e) {
    let val = e.detail.value;
    if (val == '1') {
      this.setData({
        ['dataObj.genuine']: 1
      })
    } else {
      this.setData({
        ['dataObj.genuine']: 0
      })
    }
  },

  //设置七天无理由退换
  setSeven: function(e) {
    let val = e.detail.value;
    if (val == '1') {
      this.setData({
        ['dataObj.seven_reason']: 1
      })
    } else {
      this.setData({
        ['dataObj.seven_reason']: 0
      })
    }
  },

  //是否发布YZC商品
  setYZCTag: function(e) {
    let _this = this;
    let yzcTag = e.detail.value;
    if (yzcTag == '') {
      yzcTag = 0;
    }

    this.setData({
      ['dataObj.yzc_type']: yzcTag
    })
  },

  //是否同意规则
  ruleCheck: function(e) {
    let val = e.detail.value;
    this.setData({
      ruleCheck: val
    })
  },

  //--提交表单
  formSubmit: function(e) {
    // console.log(e.detail.value);
    console.log(this.data.data);
    console.log(this.data.dataObj);
    let _this = this;

    let specData = this.data.data;
    let dataObj = this.data.dataObj;
    let skus = '';

    if (this.data.swiperImageArr.length < 1) {
      api.toast('请添加商品图片...')
      return;
    }

    if (dataObj.name == '') {
      api.toast('请填写商品标题...')
      return;
    }

    if (api.hasSpecialChar(dataObj.name, '商品名称存在非法字符', '')) {
      return
    }

    for (let i = 0; i < specData.length; i++) {
      if (dataObj.yzc_type == 1 && specData[i].yzcPrice == '') {
        api.toast('请填写商品的YZC的兑换数量...')
        return;
      }
      if (dataObj.group_booking) {
        if (specData[i].groupPrice <= 0 || specData[i].groupPrice == '') {
          api.toast('请输入正确的团购价格...')
          return;
        }
        if (specData[i].groupNum < 1 || specData[i].groupNum == '') {
          api.toast('请选择团购人数...')
          return;
        }
        if (specData[i].groupNum > specData[i].goodsNum || specData[i].goodsNum == '') {
          api.toast('库存必须大于等于拼团人数...')
          return;
        }
      } else {
        specData[i].groupPrice = '';
        specData[i].groupNum = '';
      }

      if (specData[i].goodsPrice <= 0) {
        api.toast('价格必须大于0...')
        return;
      }
      if (specData[i].goodsNum < 1) {
        api.toast('库存必须大于等于1...')
        return;
      }
      if (specData[i].goodsSpec == '' || specData[i].goodsPrice == '' || specData[i].goodsNum == '' || specData[i].imgSpec == '') {
        api.toast('请完整填写相应的商品信息...')
        return;
      }
      if (api.hasSpecialChar(specData[i].goodsSpec, '商品型号存在非法字符', '')) {
        return
      }

      skus += specData[i].goodsSpec + "," + specData[i].killPrice + "," + specData[i].goodsPrice + ",''," + specData[i].yzcPrice + "," + specData[i].groupPrice + "," + specData[i].groupNum + "," + specData[i].goodsNum + ",''," + specData[i].imgSpec + "|";
    }

    if (this.data.ruleCheck == '' && this.data.edit == 0) {
      api.toast('请阅读并勾选同意规则...')
      return;
    }

    skus = skus.substring(0, skus.length - 1); //拼接skus字符串

    if (this.data.edit != 1) {
      //--添加商品接口
      api.ajax(service.url('goodsAdd'), {
        unionid: this.data.shopData.shop_unionid,
        token: this.data.shopData.token,
        token_key: this.data.shopData.token_key,
        shop_code: this.data.shopInfo.shop_code,
        images: this.data.swiperImageArr.join('|'),
        name: dataObj.name,
        hot: dataObj.hot,
        group_booking: dataObj.group_booking,
        skus: skus,
        description: dataObj.description,
        cat_id: dataObj.cat_id,
        category_id: dataObj.category_id,
        commission1_rate: dataObj.commission1_rate,
        commission2_rate: dataObj.commission2_rate,
        genuine: dataObj.genuine,
        seven_reason: dataObj.seven_reason,
        yzc_type: dataObj.yzc_type,
        on_sale: dataObj.on_sale
      }, function(res) {
        console.log(res)
        if (res.code) {
          api.toast(res.message);
        } else {
          if (dataObj.yzc_type || dataObj.cat_id) {
            if (dataObj.yzc_type) {
              wx.showModal({
                title: '提示',
                content: '添加商品成功!\n商品需要审核，请耐心等待...\n提示：YZC商品不参与分佣',
                showCancel: false,
                success: function(res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../goods_manage/goods_manage',
                    })
                  }
                }
              })
            } else {
              wx.showModal({
                title: '提示',
                content: '添加商品成功!\n商品需要审核，请耐心等待...',
                showCancel: false,
                success: function(res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../goods_manage/goods_manage',
                    })
                  }
                }
              })
            }
          } else {
            wx.showModal({
              title: '提示',
              content: '添加商品成功!',
              showCancel: false,
              success: function(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '../goods_manage/goods_manage',
                  })
                }
              }
            })
          }
        }

      })

    } else {
      //--编辑商品接口
      api.ajax(service.url('goodsEdit'), {
        unionid: this.data.shopData.shop_unionid,
        token: this.data.shopData.token,
        token_key: this.data.shopData.token_key,
        shop_code: this.data.shopInfo.shop_code,
        goods_id: this.data.goods_id,
        images: this.data.swiperImageArr.join('|'),
        name: dataObj.name,
        hot: dataObj.hot,
        group_booking: dataObj.group_booking,
        skus: skus,
        description: dataObj.description,
        cat_id: dataObj.cat_id,
        category_id: dataObj.category_id,
        commission1_rate: dataObj.commission1_rate,
        commission2_rate: dataObj.commission2_rate,
        genuine: dataObj.genuine,
        seven_reason: dataObj.seven_reason,
        yzc_type: dataObj.yzc_type,
        on_sale: dataObj.on_sale,
      }, function(res) {
        console.log(res)

        if (res.code) {
          api.toast(res.message);
        } else {
          if (dataObj.yzc_type || dataObj.cat_id) {
            if (dataObj.yzc_type) {
              wx.showModal({
                title: '提示',
                content: '编辑商品成功!\n商品需要审核，请耐心等待...\n提示：YZC商品不参与分佣',
                showCancel: false,
                success: function(res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../goods_manage/goods_manage',
                    })
                  }
                }
              })
            } else {
              wx.showModal({
                title: '提示',
                content: '编辑商品成功!\n商品需要审核，请耐心等待...',
                showCancel: false,
                success: function(res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../goods_manage/goods_manage',
                    })
                  }
                }
              })
            }
          } else {
            wx.showModal({
              title: '提示',
              content: '编辑商品成功!',
              showCancel: false,
              success: function(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '../goods_manage/goods_manage',
                  })
                }
              }
            })
          }
        }
      })
    }
  },

  //--下架
  offButton: function(e) {
    let _this = this,
      goods_id = e.currentTarget.dataset.goodsId;
    wx.showModal({
      title: '商品下架提示',
      content: '请确认是否下架该商品',
      success: function(res) {
        if (res.confirm) {
          api.ajax(service.url('productOnSale'), {
            unionid: _this.data.shopData.shop_unionid,
            token: _this.data.shopData.token,
            token_key: _this.data.shopData.token_key,
            shop_code: _this.data.shopInfo.shop_code,
            goods_id: goods_id,
            on_sale: 0
          }, function(res) {
            if (res.code) {
              api.toast(res.message);
            } else {
              _this.setData({
                ['dataObj.on_sale']: 0
              })

              var pages = getCurrentPages();
              var prevPage = pages[pages.length - 2]; //上一个页面

              //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
              prevPage.setData({
                page: 1,
                goodsList: []
              })
              prevPage.onLoad();
              prevPage.onShow();
              api.toast('商品已下架');
            }
          })
        }
      }
    })
  },

  //--上架
  onButton: function(e) {
    let _this = this,
      goods_id = e.currentTarget.dataset.goodsId;
    api.ajax(service.url('productOnSale'), {
      unionid: this.data.shopData.shop_unionid,
      token: this.data.shopData.token,
      token_key: this.data.shopData.token_key,
      shop_code: this.data.shopInfo.shop_code,
      goods_id: goods_id,
      on_sale: 1
    }, function(res) {
      if (res.code) {
        api.toast(res.message);
      } else {
        _this.setData({
          ['dataObj.on_sale']: 1
        })

        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2]; //上一个页面

        //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
        prevPage.setData({
          page: 1,
          goodsList: []
        })
        prevPage.onLoad();
        prevPage.onShow();

        api.toast('商品已上架');
      }
    })
  },

  //--删除
  delButton: function(e) {
    let _this = this,
      goods_id = e.currentTarget.dataset.goodsId;
    wx.showModal({
      title: '商品回收提示',
      content: '请确认是否删除该商品',
      success: function(res) {
        if (res.confirm) {
          api.ajax(service.url('productDel'), {
            unionid: _this.data.shopData.shop_unionid,
            token: _this.data.shopData.token,
            token_key: _this.data.shopData.token_key,
            shop_code: _this.data.shopInfo.shop_code,
            goods_id: goods_id
          }, function(res) {
            if (res.code) {
              api.toast(res.message);
            } else {
              api.toast('商品已删除');
              wx.navigateBack({
                success: function() {
                  var pages = getCurrentPages();
                  var prevPage = pages[pages.length - 1]; //上一个页面

                  //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
                  prevPage.setData({
                    page: 1,
                    goodsList: []
                  })
                  prevPage.onLoad();
                  prevPage.onShow();
                  wx.navigateBack({
                    delta: -1
                  })
                }
              }) 
            }
          })
        }
      }
    })
  },

  //--打开添加商品规则页面
  openAddRules: function() {
    wx.navigateTo({
      url: './shop_add_rules/shop_add_rules',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let _this = this;
    this.setData({
      shopInfo: wx.getStorageSync('shopInfo'),
      shopData: wx.getStorageSync('shop_data_shop')
    })
    if (JSON.stringify(options) != '{}') {
      wx.setNavigationBarTitle({
        title: '编辑商品'
      })
      console.log(options);
      api.ajax(service.url('getGoodsDetail'), {
        unionid: this.data.shopData.shop_unionid,
        token: this.data.shopData.token,
        token_key: this.data.shopData.token_key,
        goods_id: options.goods_id
      }, function(res) {
        console.log(res);

        //--商品图片
        let swiperImageArr = [];
        if (res.data.goods_images.length > 0) {
          for (var i = 0; i < res.data.goods_images.length; i++) {
            swiperImageArr[i] = res.data.goods_images[i].url;
          }
        }

        //--商品信息
        if (res.data.goods_options.length > 0) {
          var sku = res.data.goods_options;
          for (var i = 0; i < sku.length; i++) {
            if (i != 0) {
              _this.data.templateList.push(1);
            }
            var obj = {
              groupPrice: sku[i].group_price,
              killPrice: sku[i].kill_price,
              groupNum: sku[i].group_num,
              goodsPrice: sku[i].sale_price,
              marketPrice: sku[i].market_price,
              yzcPrice: sku[i].yzc,
              goodsSpec: sku[i].name,
              goodsNum: sku[i].stock,
              imgSpec: sku[i].option_image,
            }
            _this.data.data.push(obj);
          }
        }

        //获取商品详情
        var detail_arr = res.data.description.split('><').join('>|||<').split('|||');
        //获取商品分类信息
        if (res.data.goods_categorys.length > 0) {
          var cat = res.data.goods_categorys;
          _this.data.dataObj.category_id = cat[0].category_id;
          _this.data.classify_selected_name = cat[0].name;
        }

        _this.setData({
          goods_id: options.goods_id,
          edit: 1,
          swiperImageArr: swiperImageArr,
          num: 8 - swiperImageArr.length,
          ['dataObj.name']: res.data.name,
          textNum: res.data.name.length,
          ['dataObj.hot']: res.data.hot,
          ['dataObj.group_booking']: res.data.group_booking,
          templateList: _this.data.templateList,
          data: _this.data.data,
          goodsDescriptionData: detail_arr,
          ['dataObj.cat_id']: res.data.cat_id,
          sys_cat_name: res.data.cat_name,
          ['dataObj.category_id']: _this.data.dataObj.category_id,
          classify_selected_id: _this.data.dataObj.category_id,
          classify_selected_name: _this.data.classify_selected_name,
          ['dataObj.commission1_rate']: res.data.commission1_rate,
          ['dataObj.commission2_rate']: res.data.commission2_rate,
          ['dataObj.genuine']: res.data.genuine,
          ['dataObj.seven_reason']: res.data.seven_reason,
          ['dataObj.yzc_type']: res.data.is_yzc,
          ['dataObj.on_sale']: res.data.on_sale
        })
        console.log(_this.data.data)
      })
    } else {
      let obj = {
        groupPrice: "",
        killPrice: "",
        groupNum: "",
        goodsPrice: "",
        marketPrice: "",
        yzcPrice: "",
        goodsSpec: "",
        goodsNum: "",
        imgSpec: ""
      }
      let data = this.data.data;
      data.push(obj);
      this.setData({
        data: data
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})